package com.plant.es.test.client_version.handler.action;

import com.plant.es.test.client_version.handler.EsInterface;
import org.elasticsearch.client.RestHighLevelClient;

/**
 * 2.单个
 * 文档相关操作
 */
public class DocRelated implements EsInterface {
    @Override
    public void process(RestHighLevelClient esClient) {
        //创建 user 索引的文档
//        IndexRequest request = new IndexRequest();
//        request.index("user").id("1001");
//        User user = new User("张三", "男", 30);
//        ObjectMapper mapper = new ObjectMapper();
//        String userJson = mapper.writeValueAsString(user);//对象转json字符串
//        request.source(userJson, XContentType.JSON);
//
//        IndexResponse response = esClient.index(request, RequestOptions.DEFAULT);
//        System.out.println(response);


        //更新 user 索引的文档
//        UpdateRequest request = new UpdateRequest();
//        request.index("user").id("1001");
//        request.doc(XContentType.JSON, "sex", "女");
//        UpdateResponse response = esClient.update(request, RequestOptions.DEFAULT);
//        System.out.println(response);


        //查询 user 索引的文档
//        GetRequest request = new GetRequest();
//        request.index("user").id("1001");
//        GetResponse response = esClient.get(request, RequestOptions.DEFAULT);
//        System.out.println(response);

        //删除 user 索引的文档
//        DeleteRequest request = new DeleteRequest();
//        request.index("user").id("1001");
//        DeleteResponse response = esClient.delete(request, RequestOptions.DEFAULT);
//        System.out.println(response);

    }
}
